package org.keyroy.mapEditor.ui.views;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.keyroy.map.core.animation.Animation;
import org.keyroy.map.core.manages.Resource;
import org.keyroy.map.core.manages.ResourceManage;
import org.keyroy.map.core.sprite.Sprite;
import org.keyroy.mapEditor.ui.beans.UIUtil;

public class AnimationView extends Composite {
	private Animation animation;

	public AnimationView(Composite parent) {
		super(parent, SWT.BORDER);
		RowLayout rowLayout = new RowLayout(SWT.VERTICAL);
		rowLayout.wrap = false;
		setLayout(rowLayout);
	}

	public void setAnimation(Animation animation) {
		this.animation = animation;
		if (animation != null && animation.sprites.size() > 0) {
			Sprite sprite = animation.sprites.get(0);
			Resource resource = ResourceManage.getResource(sprite.getResourceID());
			reset(resource);
		}
	}

	public void reset(Resource resource) {
		UIUtil.removeAll(this);
		if (animation != null) {
			for (int i = 0; i < animation.sprites.size(); i++) {
				Sprite sprite = animation.sprites.get(i);
				SpriteView spriteView = new SpriteView(this, false);
				spriteView.set(sprite);
			}
		}
		redraw();
	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}

}
